

class IStrategy{
    calculateRate(){
        throw new Error("calculateRate")
    }
}

class Baoxian extends IStrategy{
    calculateRate(){
        return "保费=保险金额*1年"
    }
}

class JiJin extends IStrategy{
    calculateRate(){
        return "费率= 0%"
    }
}

class LiCaizi extends IStrategy{
    calculateRate(){
        return "费率= 金额*0.015"
    }
}
/***
 * 维护一个对策略对象的引用
 */
class Context{
    constructor(strategy){
        this.strategy = strategy
    }
    executeStrategy(){
        return this.strategy.calculateRate()
    }
}

const ctx = new Context(new Baoxian())
console.log(ctx.executeStrategy());